-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
an attempt at adding retry() to trackedTask #119
base: main
Are you sure you want to change the base?
an attempt at adding retry() to trackedTask #119
Conversation
@BoussonKarel is attempting to deploy a commit to the universal-ember Team on Vercel. A member of the Team first needs to authorize it. |
@@ -193,11 +196,22 @@ export class State<Args extends any[], Return, LocalTask extends TaskIsh<Args, R | |||
return this.lastTask?.value; | |||
} | |||
|
|||
[RUN] = (positional: Args) => { | |||
[RUN] = () => { | |||
let args = this[THUNK] || DEFAULT_THUNK; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of doing this[THUNK] || DEFAULT_THUNK
here, could we move it to the constructor.
this way, we can access the args directly in here (still invoking normalizeThunk as you have it though).
@@ -69,7 +65,7 @@ export function task< | |||
|
|||
registerDestructor(state, () => state[TASK].cancelAll()); | |||
|
|||
return destroyable as unknown as TaskInstance<Return>; | |||
return destroyable as unknown as TaskInstance<Return> & { retry: () => void }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know in discord you said you might want to do the type differently -- but I think this is fine <3
@@ -195,6 +195,72 @@ module('useTask', function () { | |||
assert.true(foo.search.isFinished); | |||
assert.false(foo.search.isRunning); | |||
}); | |||
|
|||
test('it runs again when calling retry()', async function (assert) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a testing technique that might help here (and/or in a rendering test)
is using assert.step('name of thing')
and then at various intervals calling assert.verifySteps([expected steps])
-- this way you don't necessarily need to be concerned with the exact values if you don't need to be
trackedFunction has a
retry
option, but the trackedTask doesn't have this (yet).Here is an attempt at adding retry to the trackedTask.